/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.yiqi.lottery.feature.documentary.presenter;

import com.suozhang.framework.entity.bo.PageData;
import com.yiqi.lottery.entity.bo.HallBo;
import com.yiqi.lottery.feature.documentary.contract.DocumentaryContract;
import com.yiqi.lottery.feature.documentary.dependencies.hall.DaggerDocumentaryPresenterComponent;
import com.yiqi.lottery.feature.lottery.contract.HallContract;
import com.yiqi.lottery.feature.lottery.dependencies.hall.DaggerHallPresenterComponent;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import javax.inject.Inject;

/**
 *      LIJUWEN
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class DocumentaryPresenter implements DocumentaryContract.Presenter {

    private DocumentaryContract.View mView;

    @Inject

    DocumentaryContract.Model mModel;


    public DocumentaryPresenter(DocumentaryContract.View mView) {
        this.mView = mView;
        DaggerDocumentaryPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void getHallList(String keyWoed,int page,Integer bet_type,Integer tab) {
        mModel.getHallList(keyWoed,page,bet_type,tab).compose(mView.bindToLife()).subscribe(new Observer<PageData<HallBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(PageData<HallBo> stringPageData) {
                mView.dismissLoading();
                if (stringPageData.getTotal()==0){
                   mView.showHallListEmpty();
                }else {
                mView.showHallListSuccess(stringPageData);}
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showHallListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getHallMoreList(String keyword,int page,Integer bet_type,Integer tab) {
        mModel.getHallList(keyword,page,bet_type,tab).compose(mView.bindToLife()).subscribe(new Observer<PageData<HallBo>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(PageData<HallBo> stringPageData) {

                    mView.showHallListMoreSuccess(stringPageData);
            }

            @Override
            public void onError(Throwable e) {
                mView.showHallListMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {

            }
        });
    }


}
